#!/usr/bin/env python
# -*- coding: utf-8 -*-

from pymongo import MongoClient
from datetime import date, tzinfo, timedelta, datetime
from utility import *

__author__ = 'henry.woo@outlook.com'

"""
12/11/2013 15:09:28,BEST_BID,30.16,55,
12/11/2013 15:09:28,BEST_ASK,30.2,1,
12/11/2013 15:09:28,BEST_ASK,30.25,56,
12/11/2013 15:09:28,BEST_ASK,30.25,48,
12/11/2013 15:09:28,TRADE,30.16,1,465,546,OP
12/11/2013 15:09:28,TRADE,30.2,100,
12/11/2013 15:09:28,TRADE,30.25,4,900,
12/11/2013 15:09:28,BEST_BID,30.21,50,
12/11/2013 15:09:28,BEST_BID,30.21,100,
12/11/2013 15:09:28,BEST_BID,30.21,150,
12/11/2013 15:09:28,TRADE,30.25,1,000,
12/11/2013 15:09:28,BEST_BID,30.21,149,
12/11/2013 15:09:28,BEST_BID,30.21,148,
12/11/2013 15:09:28,TRADE,30.21,100,R6,IS
12/11/2013 15:09:28,TRADE,30.21,100,R6,IS
12/11/2013 15:09:28,BEST_BID,30.21,130,
12/11/2013 15:09:28,TRADE,30.21,1,800,
12/11/2013 15:09:28,BEST_ASK,30.23,3,
12/11/2013 15:09:28,BEST_BID,30.21,128,
12/11/2013 15:09:28,BEST_BID,30.21,126,
12/11/2013 15:09:28,TRADE,30.22,100,
12/11/2013 15:09:28,TRADE,30.21,200,R6,IS
12/11/2013 15:09:28,TRADE,30.21,200,R6,IS
12/11/2013 15:09:28,BEST_BID,30.21,125,
12/11/2013 15:09:28,TRADE,30.21,100,R6,IS
12/11/2013 15:09:28,TRADE,30.23,100,
12/11/2013 15:09:28,TRADE,30.228,100,T
12/11/2013 15:09:28,BEST_BID,30.21,124,
12/11/2013 15:09:28,TRADE,30.21,100,R6,IS
12/11/2013 15:09:28,BEST_BID,30.21,119,
12/11/2013 15:09:28,TRADE,30.21,500,R6,IS
12/11/2013 15:09:28,BEST_ASK,30.23,2,
12/11/2013 15:09:28,BEST_BID,30.21,115,
12/11/2013 15:09:28,TRADE,30.21,400,
12/11/2013 15:09:28,TRADE,30.21,100,
12/11/2013 15:09:28,BEST_BID,30.21,114,
12/11/2013 15:09:28,BEST_BID,30.21,113,
12/11/2013 15:09:28,TRADE,30.21,100,
12/11/2013 15:09:28,TRADE,30.23,500,T
12/11/2013 15:09:28,BEST_BID,30.21,112,
12/11/2013 15:09:28,TRADE,30.21,100,R6,IS
12/11/2013 15:09:28,BEST_BID,30.21,110,
12/11/2013 15:09:28,TRADE,30.21,200,
12/11/2013 15:09:28,BEST_ASK,30.23,1,
12/11/2013 15:09:28,BEST_ASK,30.23,1,
12/11/2013 15:09:28,BEST_BID,30.21,111,
12/11/2013 15:09:28,TRADE,30.23,100,
12/11/2013 15:09:28,TRADE,30.22,100,
12/11/2013 15:09:28,TRADE,30.22,200,
12/11/2013 15:09:28,BEST_ASK,30.23,1,
12/11/2013 15:09:28,BEST_ASK,30.25,49,
12/11/2013 15:09:28,TRADE,30.23,100,
12/11/2013 15:09:28,BEST_ASK,30.25,50,
12/11/2013 15:09:28,BEST_BID,30.21,109,
12/11/2013 15:09:28,TRADE,30.21,200,R6,IS
12/11/2013 15:09:28,TRADE,30.22,100,
12/11/2013 15:09:28,BEST_BID,30.21,107,
12/11/2013 15:09:28,TRADE,30.21,200,
12/11/2013 15:09:28,TRADE,30.22,1,138,
12/11/2013 15:09:28,BEST_BID,30.21,83,
12/11/2013 15:09:28,TRADE,30.21,100,R6,IS
12/11/2013 15:09:28,TRADE,30.21,2,400,R6,IS
12/11/2013 15:09:28,BEST_BID,30.21,43,
12/11/2013 15:09:28,TRADE,30.21,4,000,R6,IS
12/11/2013 15:09:28,BEST_BID,30.21,3,
12/11/2013 15:09:28,TRADE,30.23,100,T
12/11/2013 15:09:28,TRADE,30.21,4,000,R6,IS
12/11/2013 15:09:28,TRADE,30.23,100,T
12/11/2013 15:09:28,BEST_BID,30.16,55,
12/11/2013 15:09:28,TRADE,30.21,300,R6,IS
12/11/2013 15:09:28,TRADE,30.22,100,
12/11/2013 15:09:28,TRADE,30.16,300,T
12/11/2013 15:09:28,TRADE,30.16,400,T
12/11/2013 15:09:28,TRADE,30.17,200,
12/11/2013 15:09:28,BEST_ASK,30.21,1,
12/11/2013 15:09:28,TRADE,30.185,100,T
12/11/2013 15:09:28,TRADE,30.185,100,
12/11/2013 15:09:28,BEST_BID,30.16,48,
12/11/2013 15:09:28,TRADE,30.16,700,R6,IS
12/11/2013 15:09:28,BEST_BID,30.16,47,
12/11/2013 15:09:28,TRADE,30.16,100,R6,IS
12/11/2013 15:09:28,BEST_BID,30.16,48,
"""



time1 = '12/11/2013 15:09:28'
dt=datetime.strptime(time1, "%Y-%m-%d %H:%M:%S")
d={
    'symbol':'ATHM',
    'timestamp':dt,
    'date':dt.strftime("%Y-%m-%d"),
    'time':dt.strftime("%H:%M:%S"),
    'bids':[{'price':30.16, 'vol':55},{'price':30.21, 'vol':50}],
    'asks':[{'price':30.2, 'vol':1},{'price':30.25, 'vol':56},{'price':30.25, 'vol':48}],
    'trades':[{'price':30.16, 'vol':1465546,'cc':'OP'},{'price':30.2, 'vol':100}]
}

client = MongoClient('mongodb://localhost:27017/')
db=client.twintowers
db.tickdata.insert(d)

import pytz, datetime
#local = pytz.timezone ("America/New_York")
local = pytz.utc
#sg = pytz.timezone ('Asia/Singapore')
naive = datetime.datetime.strptime ("2013-12-11 14:30:00", "%Y-%m-%d %H:%M:%S")
#local_dt = local.localize(naive, is_dst=False)
local_dt = local.localize(naive, is_dst=False)
nytz = pytz.timezone ("America/New_York")
nytime = local_dt.astimezone(nytz)


